<template>
  <!-- 详情 -->
  <el-dialog
    width="600px"
    :title="$t('详情')"
    destroy-on-close
    append-to-body
    :visible.sync="show"
    :before-close="cancel"
  >
    <el-form ref="elForm" :model="form" :rules="rules" size="small">
      <el-form-item :label="$t('备注')" prop="remark">
        <el-input v-model="form.remark" type="textarea" :rows="5" />
      </el-form-item>
    </el-form>

    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel">
        <!-- 关闭 -->
        {{ $t("关闭") }}
      </el-button>
      <el-button @click="handleSubmit" type="primary">
        <!-- 确认 -->
        {{ $t("确定") }}
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
import { updateStockCheckRemark } from "@/api/distribution/sku/Inventory";

export default {
  activated() {
    this.$nextTick(() => this.$refs['TableRef']?.doLayout())
  },
  props: {
    /**
     * formData
     */
    formData: {
      type: Object,
      required: true,
    },
    /**
     * 控制显示隐藏
     */
    show: {
      type: Boolean,
      required: true,
      default: false,
    },
  },
  data() {
    return {
      form: {
        remark: "",
      },
      rules: {
        remark: [
          {
            required: true,
            message: this.$t("请输入"),
            trigger: "blur",
          },
        ],
      },
    };
  },
  watch: {
    show: function (newValue) {
      if (newValue) {
        this.form.remark = this.formData.remark || "";
      }
    },
  },
  methods: {
    handleSubmit() {
      this.$refs.elForm.validate((valid) => {
        if (valid) {
          updateStockCheckRemark(this.formData.id,this.form.remark).then((res) => {
            const { code, data, msg } = res;
            if (code === 200) {
              this.$message({ type: 'success', message: msg})
;
              this.cancel();
              this.$emit("close");
            }
          });
        }
      });
    },
    getList() {},

    cancel() {
      this.$emit("update:show", false);
    },
  },
};
</script>
<style scoped lang="scss"></style>
